/**
 * @param {number[][]} intervals
 * @return {number}
 */
var eraseOverlapIntervals = function(intervals) {
  let count = 0, nowMax;
  intervals = intervals.sort((a, b) => a[1] - b[1]);
  nowMax = intervals[0][1];
  console.log(intervals);
  for(let i = 1; i < intervals.length; i++) {
    if(nowMax > intervals[i][0]) {
      count++;
    } else {
      nowMax = intervals[i][1];
    }
  }
  return count;
};
let intervals = [[1,2],[2,3],[3,4],[1,3]];
console.log(eraseOverlapIntervals(intervals));
intervals = [ [1,2], [1,2], [1,2] ];
console.log(eraseOverlapIntervals(intervals));
intervals = [ [1,2], [2,3] ];
console.log(eraseOverlapIntervals(intervals));
intervals = [[1,100],[11,22],[1,11],[2,12]];
console.log(eraseOverlapIntervals(intervals));
intervals = [[-52,31],[-73,-26],[82,97],[-65,-11],[-62,-49],[95,99],[58,95],[-31,49],[66,98],[-63,2],[30,47],[-40,-26]];
console.log(eraseOverlapIntervals(intervals));

